import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: "/index",
    component: () => import("@/views/index.vue"),
    name: "index"
  },
  {
    path: "/course",
    component: () => import("@/views/course.vue"),
    name: "course"
  },
  {
    path: "/practice",
    component: () => import("@/views/practice.vue"),
    name: "practice"
  },
  {
    path: "/record",
    component: () => import("@/views/record.vue"),
    name: "record"
  },
  {
    path: "/setinfo",
    component: () => import("@/views/setinfo.vue"),
    name: "setinfo"
  },
  {
    path: "/user",
    component: () => import("@/views/user.vue"),
    name: "user",
    children: [
      {
        path: "/userindex",
        component: () => import("@/components/mine/index.vue"),
        name: "userindex"
      }
    ]
  },
  {
    path: "/custmoer",
    component: () => import("@/views/custmoer.vue"),
    name: "custmoer"
  },
  {
    path: "/smslogin",
    component: () => import("@/views/smslogin.vue"),
    name: "smslogin"
  },
  {
    path: "/login",
    component: () => import("@/views/login.vue"),
    name: "login"
  },
  {
    path: "/detail",
    component: () => import("@/views/detail.vue"),
    name: "detail"
  },
  {
    path: "/info",
    component: () => import("@/components/mine/info.vue"),
    name: "info"
  },
  {
    path: "/teach",
    component: () => import("@/views/teach.vue"),
    name: "teach"
  },
  {
    path: "/concern",
    component: () => import("@/views/concern.vue"),
    name: "concern"
  },
  {
    path: "/setpassword",
    component: () => import("@/views/setpassword.vue"),
    name: "setpassword"
  },
  {
    path: "/setinfoy",
    component: () => import("@/views/setinfoy.vue"),
    name: "setinfoy"
  },
  {
    path: "/options",
    component: () => import("@/views/options.vue"),
    name: "options"
  },
  {
    path: "/cdetail",
    component: () => import("@/views/cdetail.vue"),
    name: "cdetail"
  },
  {
    path: "/",
    redirect: "/index"
  }
]

const originalPush=VueRouter.prototype.push
//重写push函数
VueRouter.prototype.push=function push(location){
  return originalPush.call(this,location).catch(err=>err)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
